package com.lines.chap02;

import org.springframework.util.StopWatch;

import java.io.*;
import java.util.stream.IntStream;

/**
 * <p>
 * <code>AgeStas</code>
 * </p>
 *
 * @author junbao3
 * TODO
 * @date 2023-03-23 10:40
 * Copyright (C) 2021 IFlyTek. All rights reserved.
 */
public class AgeStas {
    public static void main(String[] args) throws IOException {
        String str = null;
        String fileName = "F:\\age.txt";
        InputStreamReader isr = new InputStreamReader(new FileInputStream(fileName),"UTF-8");
        StopWatch stopWatch = new StopWatch();

        stopWatch.start();
        BufferedReader br = new BufferedReader(isr);
        int total = 0;
        int data[] = new int[130];
        while ((str = br.readLine())!=null){
            Integer age = Integer.valueOf(str);
            data[age]++;
            total++;
        }
        System.out.println("总数据："+total);
        IntStream.range(0,130).forEach(i->{
            System.out.println(i+":"+data[i]);
        });
        stopWatch.stop();
        //O(n) 14亿   最垃圾的cpu 100万/秒 *1000 =10亿 10亿的数据需要1000s
        // 时间复杂度 预计时间 100-1000秒之前  500秒以下
        //实测 63秒 如果是Linux服务器 还可以快10倍
        //63843
        System.out.println(stopWatch.prettyPrint());
    }
}
